<template>
	<Layout>
		<template #title>律{{lawFirmType=='2'?'所':'师'}}案例</template>
		<ScrollRefresher @refresh="loadData">
			<view v-for="item of list" :key="item.id" class="lawyer-case">
				<view class="lawyer-case__box" @click.stop="tapDetail(item.id)">
					<view class="lawyer-case__image aspect-fill">
					<image mode="aspectFill" :src="item.caseImage"></image>
					</view>
					<view class="lawyer-case__intro">
						<view class="ellipsis-line-clamp">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
		</ScrollRefresher>
	</Layout>
</template>

<script setup lang="ts" name="LawyerCase">
	import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app';
	import { getLawfirmCaseList } from '@/apis/lawfirm';
	import { ref } from 'vue';
	import type { AnyObj } from '@/types/global';

	let lawFirmId = '';
	const list = ref<AnyObj[]>([]);
	const lawFirmType = ref('1');

	function tapDetail(id : string) {
		uni.navigateTo({
			url: `/pages-lawyer/case-detail/case-detail?id=${id}`
		})
	}

	function loadData() {
		getLawfirmCaseList(lawFirmId).then((res) => {
			list.value = res.rows ?? [];
		});
	}


	onPullDownRefresh(() => {
		loadData();
		setTimeout(() => {
			uni.stopPullDownRefresh();
		}, 500);
	});

	onLoad((options) => {
		options = options as { lawFirmId : string; lawFirmType : string; }
		lawFirmId = options.lawFirmId;
		lawFirmType.value = options.lawFirmType;
		loadData();
	});
</script>